package com.css.zfzx.sjcj.modules.qhsiteclassresult.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.zfzx.sjcj.common.utils.*;
import com.css.zfzx.sjcj.modules.boundary.Point;
import com.css.zfzx.sjcj.modules.pchjdzb.service.PcHjDzbService;
import com.css.zfzx.sjcj.modules.qhmapfiles.repository.QhMapFilesImport;
import com.css.zfzx.sjcj.modules.qhmapfiles.repository.entity.QhMapFilesEntity;
import com.css.zfzx.sjcj.modules.qhmapfiles.viewobjects.QhMapFilesQueryParams;
import com.css.zfzx.sjcj.modules.qhsiteclassresult.repository.QhSiteClassResultNativeRepository;
import com.css.zfzx.sjcj.modules.qhsiteclassresult.repository.QhSiteClassResultRepository;
import com.css.zfzx.sjcj.modules.qhsiteclassresult.repository.QhSiteClassUtil;
import com.css.zfzx.sjcj.modules.qhsiteclassresult.repository.entity.QhSiteClassResultEntity;
import com.css.zfzx.sjcj.modules.qhsiteclassresult.repository.QhSiteClassResultImport;
import com.css.zfzx.sjcj.modules.qhsiteclassresult.service.QhSiteClassResultService;
import com.css.zfzx.sjcj.modules.qhsiteclassresult.viewobjects.QhSiteClassResultQueryParams;
import com.css.bpm.platform.utils.*;
import com.css.zfzx.sjcj.modules.qhsiteclassresult.viewobjects.QhSiteClassResultVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.opengis.feature.simple.SimpleFeature;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * @author andy
 * @date 2021-01-26
 */
@Service
@Slf4j
public class QhSiteClassResultServiceImpl implements QhSiteClassResultService {

	@Autowired
    private QhSiteClassResultRepository qhSiteClassResultRepository;
    @Autowired
    private QhSiteClassResultNativeRepository qhSiteClassResultNativeRepository;
    @Autowired
    private QhSiteClassResultImport qhSiteClassResultInitial;
    @Autowired
    private QhMapFilesImport qhMapFilesImport;//上传文件管理
    @Autowired
    private PcHjDzbService pcHjDzbService;
    @Autowired
    private QhSiteClassResultService qhSiteClassResultService;

    @Override
    public JSONObject queryQhSiteClassResults(QhSiteClassResultQueryParams queryParams, int curPage, int pageSize) {
        Page<QhSiteClassResultEntity> qhSiteClassResultPage = this.qhSiteClassResultNativeRepository.queryQhSiteClassResults(queryParams, curPage, pageSize);
        JSONObject jsonObject = PlatformPageUtils.formatPageData(qhSiteClassResultPage);
        return jsonObject;
    }

    @Override
    public JSONObject queryQhSiteClassResultsByFileName(QhSiteClassResultQueryParams queryParams, int curPage, int pageSize, String sort, String order) {
        if (!PlatformObjectUtils.isEmpty(sort) && sort.length() > 0) {
            sort = CheckObjFields.propertyChange(sort);
        }
        Page<QhSiteClassResultEntity> qhSiteClassResultPage = this.qhSiteClassResultNativeRepository.queryQhSiteClassResultsByFileName(queryParams, curPage, pageSize, sort, order);
        JSONObject jsonObject = PlatformPageUtils.formatPageData(qhSiteClassResultPage);
        return jsonObject;
    }

    @Override
    public QhSiteClassResultEntity getQhSiteClassResult(String id) {
        QhSiteClassResultEntity qhSiteClassResult = this.qhSiteClassResultRepository.findById(id).orElse(null);
         return qhSiteClassResult;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public QhSiteClassResultEntity saveQhSiteClassResult(QhSiteClassResultEntity qhSiteClassResult) {
        String uuid = UUIDGenerator.getUUID();
        qhSiteClassResult.setUuid(uuid);
        qhSiteClassResult.setCreateUser(PlatformSessionUtils.getUserId());
        qhSiteClassResult.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        this.qhSiteClassResultRepository.save(qhSiteClassResult);
        return qhSiteClassResult;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public QhSiteClassResultEntity updateQhSiteClassResult(QhSiteClassResultEntity qhSiteClassResult) {
        qhSiteClassResult.setUpdateUser(PlatformSessionUtils.getUserId());
        qhSiteClassResult.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        String id = qhSiteClassResult.getUuid();
        QhSiteClassResultEntity one = qhSiteClassResultRepository.findById(id).get();
        BeanUtil.copyPropertiesIgnoreNull(qhSiteClassResult, one);
        this.qhSiteClassResultRepository.save(one);
        return qhSiteClassResult;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteQhSiteClassResults(List<String> ids) {
        List<QhSiteClassResultEntity> qhSiteClassResultList = this.qhSiteClassResultRepository.findAllById(ids);
        if(!PlatformObjectUtils.isEmpty(qhSiteClassResultList) && qhSiteClassResultList.size() > 0) {
            for(QhSiteClassResultEntity qhSiteClassResult : qhSiteClassResultList) {
                this.qhSiteClassResultRepository.delete(qhSiteClassResult);
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteQhSiteClassResultsByFileName(List<String> fileNames) {
        for (int i = 0; i < fileNames.size(); i++) {
            QhSiteClassResultQueryParams queryParams = new QhSiteClassResultQueryParams();
            queryParams.setAffiliatedFileName(fileNames.get(i));
            System.out.println(new Date()+"----开始删除." + fileNames.get(i));
            List<String> uuidList = this.qhSiteClassResultNativeRepository.listQhSiteClassResultsUuidsByJDBC(queryParams);
            if(!PlatformObjectUtils.isEmpty(uuidList) && uuidList.size() > 0) {
                System.out.println(new Date()+"----开始逻辑删除." + uuidList.size() + "条数据");
                //物理删
                //qhSiteClassResultInitial.sqlBatchDeleteEntities(qhSiteClassResultList);
                qhSiteClassResultInitial.newSqlBatchLogicDeleteEntities(uuidList);
                System.out.println(new Date()+"----结束逻辑删除." + uuidList.size() + "条数据");
            }
            //查询上传文件表
            QhMapFilesQueryParams qhMapFilesQueryParams = new QhMapFilesQueryParams();
            qhMapFilesQueryParams.setAffiliatedFileName(fileNames.get(i));
            qhMapFilesQueryParams.setType("SCR_");//上传类型（PED_,RLM_,RLMPolygon_,SCR_）
            qhMapFilesQueryParams.setIsDelete("0");//未删除
            List<QhMapFilesEntity> list = qhMapFilesImport.searchMapFiles(qhMapFilesQueryParams);
            if(!PlatformObjectUtils.isEmpty(list) && list.size() > 0) {
                //逻辑删--上传文件表
                qhMapFilesImport.sqlBatchLogicDeleteEntities(list);
            }
            System.out.println(new Date()+"----结束删除." + fileNames.get(i));
        }
    }

    @Override
    public JSONObject getQhSiteClassResults(QhSiteClassResultQueryParams queryParams) {
        List<QhSiteClassResultEntity> qhSiteClassResults = this.qhSiteClassResultNativeRepository.listQhSiteClassResults(queryParams);
        for (QhSiteClassResultEntity scrEntity : qhSiteClassResults) {
            String coords = scrEntity.getCoordinates();
            if (coords == null) continue;
            coords = coords.toLowerCase();
            if (coords.indexOf("multipolygon") != -1) {
                coords = coords.substring(coords.indexOf("(((") + 3, coords.lastIndexOf(")))"));
                coords = coords.replace(")), ((", "|");
                coords = coords.replace("), (", "#");
                scrEntity.setCoordinates(coords);
            } else if (coords.indexOf("polygon") != -1) {
                String sp = coords.indexOf("),(") != -1 ? "),(" : (coords.indexOf("), (") != -1 ? "), (" : "");
                String oldWkt = coords, coordinate = "";
                if ("".equals(sp)) {
                    oldWkt = oldWkt.substring(oldWkt.indexOf("(") + 2, oldWkt.lastIndexOf("))"));
                    String[] coordinates = oldWkt.split(",");
                    for (int i = 0; i < coordinates.length; i++) {
                        String[] _coords = coordinates[i].split(" ");
                        coordinate += _coords[0] + " " + _coords[1] + ",";
                    }
                    coordinate = coordinate.substring(0, coordinate.length() - 1);
                    scrEntity.setCoordinates(coordinate);
                } else {
                    oldWkt = oldWkt.replace(sp, "#"); sp = "#";
                    String[] coordinates = oldWkt.split(sp); String tempCoordinate = "";
                    for (int i = 0; i < coordinates.length; i++) {
                        tempCoordinate = coordinates[i];
                        String[] _coords = tempCoordinate.split(","), __coords = null;
                        for (int j = 0; j < _coords.length; j++) {
                            __coords = _coords[j].split(" ");
                            coordinate += __coords[0] + " " + __coords[1] + ",";
                        }
                        coordinate = coordinate.substring(0, coordinate.length() - 1) + "|";
                    }
                    scrEntity.setCoordinates(coordinate);
                }
            }
            //scrEntity.setCoordinates(ProjectTransUtil.parseWktPolygon(scrEntity.getCoordinates()));
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", qhSiteClassResults);
        return jsonObject;
    }

    private void deleteData(String province, String city, String area) {
        QhSiteClassResultQueryParams queryParams = new QhSiteClassResultQueryParams();
        queryParams.setProvince(province);
        queryParams.setCity(city);
        queryParams.setArea(area);
        List<QhSiteClassResultEntity> scrEntities = qhSiteClassResultNativeRepository.listQhSiteClassResults(queryParams);
        List<String> ids = new ArrayList<>();
        for (int i = 0; i < scrEntities.size(); i++) {
            ids.add(scrEntities.get(i).getUuid());
        }
        this.deleteQhSiteClassResults(ids);
    }

    @Override
    public void saveOrUpdate(QhSiteClassResultEntity scrEntity) {
        /*QhSiteClassResultQueryParams queryParams = new QhSiteClassResultQueryParams();
        queryParams.setObjectid(scrEntity.getObjectid());
        queryParams.setObjectid1(scrEntity.getObjectid1());
        queryParams.setProvince(scrEntity.getProvince());
        queryParams.setCity(scrEntity.getCity());
        queryParams.setArea(scrEntity.getArea());
        List<QhSiteClassResultEntity> scrEntities = qhSiteClassResultNativeRepository.listQhSiteClassResults(queryParams);
        List<String> ids = new ArrayList<>();
        for (int i = 0; i < scrEntities.size(); i++) {
            ids.add(scrEntities.get(i).getUuid());
        }
        this.deleteQhSiteClassResults(ids);*/
        this.saveQhSiteClassResult(scrEntity);
        /*
        // 若查到数据为空，则新增
        if (CollectionUtils.isEmpty(scrEntities)) {
            this.saveQhSiteClassResult(scrEntity);
        } else {
            if (scrEntities.size() == 1) {
                QhSiteClassResultEntity sourceProvinceEntity = scrEntities.get(0);
                BeanUtil.copyPropertiesIgnoreNull(scrEntity, sourceProvinceEntity);
                this.updateQhSiteClassResult(sourceProvinceEntity);
            } else {
                throw new RuntimeException("库中该数据最多一条，请管理员清理数据库冗余数据！");
            }
        }*/
    }

    @Override
    public String judgeFileParams(String[] datas) {
        String str = "";
        Set<String> set = new HashSet<String>(Arrays.asList(datas));
        if(!set.contains("OBJECTID_1")){
            str += "OBJECTID_1,";
        }
        if(!set.contains("OBJECTID")){
            str += "OBJECTID,";
        }
        if(!set.contains("usa_classi")){
            str += "usa_classi,";
        }
        if(!set.contains("Shape_Leng")){
            str += "Shape_Leng,";
        }
        if(!set.contains("Shape_Le_1")){
            str += "Shape_Le_1,";
        }
        if(!set.contains("Shape_Area")){
            str += "Shape_Area,";
        }
        return str;
    }

    @Override
    public JSONObject searchQhSiteClassResults(QhSiteClassResultQueryParams queryParams) {
        List<QhSiteClassResultEntity> qhSiteClassResults = this._searchQhSiteClassResults(queryParams);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", qhSiteClassResults);
        return jsonObject;
    }
    private List<QhSiteClassResultEntity> _searchQhSiteClassResults(QhSiteClassResultQueryParams queryParams) {

        List<QhSiteClassResultEntity> result = new ArrayList<>();

        float minLon = 0.0f, minLat = 0.0f, maxLon = 0.0f, maxLat = 0.0f;

        Map<String, String> coords = null;
        String coordinate = "";
        String province = queryParams.getProvince(), city = queryParams.getCity(), area = queryParams.getArea();
        String bounds = queryParams.getBounds(), level = "", tempLevel = "";
        int zoom = queryParams.getZoom(), minLevel = 0, maxLevel = 0;

        String[] levels = QhSiteClassUtil.levels, tempLevels;
        for (int i = 0; i < levels.length; i++) {
            tempLevel = levels[i];
            tempLevels = tempLevel.split("-");
            minLevel = Integer.parseInt(tempLevels[0]); maxLevel = Integer.parseInt(tempLevels[1]);
            if (zoom >= minLevel && zoom <= maxLevel) {
                level = tempLevel;
                break;
            }
        }
        if ("".equals(level)) level = levels[0];

        Point[] boundary = new Point[]{new Point(0, 0)};
        if (!PlatformObjectUtils.isEmpty(queryParams.getBounds())) {
            String bound = queryParams.getBounds();
            String[] coordinates = bound.split(",");
            String[] coords0 = coordinates[0].split(" ");
            String[] coords1 = coordinates[1].split(" ");
            minLon = Float.parseFloat(coords0[0]); minLat = Float.parseFloat(coords0[1]); maxLon = Float.parseFloat(coords1[0]); maxLat = Float.parseFloat(coords1[1]);
            boundary = QhSiteClassUtil.wrapBoundary(minLon, minLat, maxLon, maxLat);
        }

        String district = "";
        if ("".equals(province) && "".equals(city) && "".equals(area)) {
            coordinate = "";
        } else if (!"".equals(province) && "".equals(city) && "".equals(area)) {
            district = level + "#" + province + "-" + city + "-" + area;
            coords = AreaBoundaryUtil.getProvinceBoundary(province);
            coordinate = coords.get(province);
        } else if (!"".equals(province) && !"".equals(city) && "".equals(area)) {
            district = level + "#" + province + "-" + city + "-" + area;
            Map<String, String> city2boundary = AreaBoundaryUtil.getAllCitiesBoundaryByProvince(province);
            coordinate = city2boundary.get(city);
        } else if (!"".equals(province) && !"".equals(city) && !"".equals(area)) {
            district = level + "#" + province + "-" + city + "-" + area;
            Map.Entry<String, Map<String, String>> tempCoords = AreaBoundaryUtil.getCoordsByCityName(province, city);
            Map<String, String> area2boundary = tempCoords.getValue();
            coordinate = area2boundary.get(area);
        }

        if (!"".equals(district) && QhSiteClassUtil.districtToEntities.containsKey(district)) return QhSiteClassUtil.districtToEntities.get(district);

        if ("".equals(coordinate)) {
            result = QhSiteClassUtil.getRaw2EntitiesByBoundary(new Point[0], level, boundary, true, null);
        } else if (coordinate != null) {
            Map<String, List<Integer>> already = new HashMap<>();
            String[] coordinates = StringUtils.split(coordinate, "|");
            for (int j = 0; j < coordinates.length; j++) {
                String[] lonlats = StringUtils.split(coordinates[j], ";");
                Point[] points = new Point[lonlats.length];
                for (int i = 0; i < lonlats.length; i++) {
                    String[] lonlat = StringUtils.split(lonlats[i], ",");
                    Point point = new Point();
                    point.x = Double.parseDouble(lonlat[0]);
                    point.y = Double.parseDouble(lonlat[1]);
                    points[i] = point;
                }
                List<QhSiteClassResultEntity> temp = QhSiteClassUtil.getRaw2EntitiesByBoundary(points, level, boundary, false, already);
                result.addAll(temp);
            }
        }
        if (!"".equals(district)) QhSiteClassUtil.districtToEntities.put(district, result);
        //System.out.println("查询完成!");
        return result;
    }

    //保存到上传文件管理表
    private void saveMapFiles(QhMapFilesEntity qhMapFilesEntity) throws Exception {
        List<QhMapFilesEntity> list = new ArrayList<QhMapFilesEntity>();
        list.add(qhMapFilesEntity);
        String affiliatedFileName = qhMapFilesEntity.getAffiliatedFileName();
        String province = qhMapFilesEntity.getProvince();
        String city = qhMapFilesEntity.getCity();
        String area = qhMapFilesEntity.getArea();
        //逻辑删除未保存的文件
        deleteMapFileByParams(affiliatedFileName, province, city, area);
        //保存
        qhMapFilesImport.sqlBatchSaveEntities(list);
    }

    //逻辑删除未保存的文件
    private void deleteMapFileByParams(String affiliatedFileName, String province, String city, String area) {
        //查询上传文件表
        QhMapFilesQueryParams qhMapFilesQueryParams = new QhMapFilesQueryParams();
        qhMapFilesQueryParams.setProvince(province);
        qhMapFilesQueryParams.setCity(city);
        qhMapFilesQueryParams.setArea(area);
        //qhMapFilesQueryParams.setAffiliatedFileName(affiliatedFileName);
        qhMapFilesQueryParams.setType("SCR_");//上传类型（PED_,RLM_,RLMPolygon_,SCR_）
        //查询文件（未删除）
        List<QhMapFilesEntity> list = qhMapFilesImport.searchMapFilesUnSaved(qhMapFilesQueryParams);
        if(!PlatformObjectUtils.isEmpty(list) && list.size() > 0) {
            //逻辑删--上传文件表
            qhMapFilesImport.sqlBatchLogicDeleteEntities(list);
        }
    }

    //校验shp文件
    public String checkSHPFiles(String filePath, String province, String city, String area) {
        System.out.println(new Date()+"-------------------1.开始readSHPFile");
        String prjPath = filePath.substring(0, filePath.length() - 4) + ".prj";
        String strWKTMercator = VectorDataUtil.readPRJ(prjPath);
        if (strWKTMercator != "") ProjectTransUtil.setStrWKTMercator(strWKTMercator);
        System.out.println(new Date()+"-------------------2.开始校验");
        /*//读取shp文件并校验--type上传类型（PED_,RLM_,RLMPolygon_,SCR_）
        List<Object> list = VectorDataUtil.readSHPFileCheck(filePath, "UTF-8","SCR_", null);
        String codeType = (String) list.get(0);//编码类型（0：UTF-8，1：GBK）
        int dataLength = (int) list.get(1);//数据长度
        String checkResult = (String) list.get(2);//校验结果
        //编码类型（0：UTF-8，1：GBK）
        if (codeType.equals("UTF-8")) {
            codeType = "0";
        }else{
            codeType = "1";
        }
        if(checkResult.equals("校验成功")){
            System.out.println(new Date()+"-------------------1.完成校验GeometryIsNotEqualsCoordinate");
            System.out.println(new Date()+"-------------------2.完成校验是否有乱码");
            System.out.println(new Date()+"-------------------3.完成校验字段空值");
            System.out.println(new Date()+"-------------------4.完成校验空间分辨率是否为6秒");
            System.out.println(new Date()+"-----------校验成功.");
        }else{
            System.out.println(new Date()+"-----------校验失败."+checkResult);
            return checkResult;
        }
        System.out.println(new Date()+"-----------3.结束校验");*/

        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length() - 4);
        // 返回的消息
        StringBuilder returnMsg = new StringBuilder();
        /* //上传文件信息
        QhMapFilesEntity qhMapFilesEntity = new QhMapFilesEntity();
        qhMapFilesEntity.setFilepath(filePath);
        qhMapFilesEntity.setProvince(province);
        qhMapFilesEntity.setCity(city);
        qhMapFilesEntity.setArea(area);
        qhMapFilesEntity.setAffiliatedFileName(fileName);
        qhMapFilesEntity.setIsSave("0");
        qhMapFilesEntity.setIsDelete("0");
        qhMapFilesEntity.setType("SCR_");//类型
        qhMapFilesEntity.setPostfix("shp");
        qhMapFilesEntity.setQualityStatus("1");//上传省市级类型（0：省，1：市）
        qhMapFilesEntity.setCodeType(codeType);//编码类型（0：UTF-8，1：GBK）
        qhMapFilesEntity.setDataLength(dataLength);//数据长度*/
        try {
            System.out.println(new Date()+"-------------------4.开始保存");
            //保存到上传文件管理表
            //this.saveMapFiles(qhMapFilesEntity);
            String createUser = PlatformSessionUtils.getUserId();
            createUser = (createUser != null ? createUser : "");
            /*if (codeType.equals("0")) {
                codeType = "UTF-8";
            }else{
                codeType = "GBK";
            }*/
            //test
            String codeType = "UTF-8";//编码类型（0：UTF-8，1：GBK）
            int dataLength = 0;
            String result = this.qhSiteClassResultService.newImportShapeFile(filePath,province,city,area,createUser,codeType,dataLength);
            //已保存成功
            if(result.contains("成功导入")){
                result = "导入成功." + result;
            }else{
                result = "导入失败." + result;
            }
            System.out.println(new Date()+"-------------------5.结束保存");
            //returnMsg.append("等待导入" + dataLength + "条数据.请第二天查询上传内容.");
            returnMsg.append(result);
            return returnMsg.toString();
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
            return "插入或更新数据出现错误: <br/>" + e.getMessage();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "数据导入失败, 服务器内部出现异常!";
        }
    }

    /*//保存--zyt
    @Override
    public String newImportShapeFile(String filePath, String province, String city, String area, String createUser,String codeType,int dataLength) {
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length() - 4);
        String prjPath = filePath.substring(0, filePath.length() - 4) + ".prj";
        String strWKTMercator = VectorDataUtil.readPRJ(prjPath);
        if (strWKTMercator != "") ProjectTransUtil.setStrWKTMercator(strWKTMercator);
        // 返回的消息
        StringBuilder returnMsg = new StringBuilder();

        List<QhSiteClassResultVo> scrVOs = new ArrayList<QhSiteClassResultVo>();
        System.out.println(new Date()+"-------------------1.开始readSHPFile");
        SimpleFeatureCollection colls = VectorDataUtil.readShp(filePath, codeType);
        System.out.println(new Date()+"-------------------2.结束readSHPFile");
        //zyt-test
        int size = 0;
        boolean tempBool = true;//判断是否需要转换经纬度值
        String lonLatStr = "", wkt = "";
        SimpleFeatureIterator iters = colls.features();
        while (iters.hasNext()) {
            SimpleFeature sf = iters.next();
            List<Object> values = sf.getAttributes();
            size = values.size();
            if(tempBool){
                wkt = values.get(0).toString();
                if (wkt.indexOf("MULTIPOINT") != -1) {
                    lonLatStr = VectorDataUtil.reverseWktMultiPoint(ProjectTransUtil.wkt2lonLat(wkt));
                } else if (wkt.indexOf("POINT") != -1) {
                    lonLatStr = VectorDataUtil.reverseWktPoint(ProjectTransUtil.wkt2lonLat(wkt));
                } else if (wkt.indexOf("MULTIPOLYGON") != -1) {
                    lonLatStr = VectorDataUtil.reverseWktMultiPolygon(ProjectTransUtil.wkt2lonLat(wkt));
                } else if (wkt.indexOf("POLYGON") != -1) {
                    lonLatStr = VectorDataUtil.reverseWktPolygon(ProjectTransUtil.wkt2lonLat(wkt));
                }
                values.set(0, lonLatStr);
                //判断是否经纬度值是否相等
                if(wkt.equals(lonLatStr)){
                    tempBool = false;//判断是否需要转换经纬度值
                }
            }
            QhSiteClassResultVo scrVO = new QhSiteClassResultVo();
            scrVO.setProvince(province);
            scrVO.setCity(city);
            scrVO.setArea(area);
            scrVO.setAffiliatedFileName(fileName);

            scrVO.setCoordinates(values.get(0).toString());
            String usaClassi = values.get(1).toString();
            scrVO.setUsaClassi(VectorDataUtil.transUsaClassi(usaClassi));
            if (size >= 3) scrVO.setShapeLeng(Double.parseDouble(values.get(2).toString()));
            if (size >= 4) scrVO.setShapeLe1(Double.parseDouble(values.get(3).toString()));
            if (size >= 5) scrVO.setShapeArea(Double.parseDouble(values.get(4).toString()));

            scrVOs.add(scrVO);
        }
        iters.close();
        System.out.println(new Date()+"-------------------3.结束校验");
        try {
            System.out.println(new Date()+"-------------------4.开始保存");
            //保存--zyt
            this.newSaveData(scrVOs,createUser);
            //保存一条记录：dataType(1:PGA,2等级图矢量点)
            //pcHjDzbService.jdbcSave(province, city, area,"10");
            System.out.println(new Date()+"-------------------5.结束保存");
            returnMsg.append("成功导入" + scrVOs.size() + "条数据.");
            return returnMsg.toString();
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
            return "插入或更新数据出现错误: <br/>" + e.getMessage();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "数据导入失败, 服务器内部出现异常!";
        }
    }*/

    //保存--zyt
    @Override
    public String newImportShapeFile(String filePath, String province, String city, String area, String createUser,String codeType,int dataLength) {
        // 返回的消息
        StringBuilder returnMsg = new StringBuilder();
        try {
            System.out.println(new Date()+"-------------------1.开始保存");
            //保存--zyt
            int count = this.newSaveData(filePath,province,city,area, codeType, dataLength,createUser);
            System.out.println(new Date()+"-------------------2.结束保存");
            returnMsg.append("成功导入" + count + "条数据.");
            return returnMsg.toString();
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
            return "插入或更新数据出现错误: <br/>" + e.getMessage();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "数据导入失败, 服务器内部出现异常!";
        }
    }

    /*//保存--zyt
    private void newSaveData(List<QhSiteClassResultVo> list,String createUser) throws Exception {
        List<QhSiteClassResultEntity> scrs = new ArrayList<>();
        System.out.println(new Date()+"-------------------4.开始保存--开始将VO数据映射拷贝到库表中");
        for (int i = 0; i < list.size(); i++) {
            QhSiteClassResultEntity scrEntity = new QhSiteClassResultEntity();
            QhSiteClassResultVo scrVO = list.get(i);
            // 将VO数据映射拷贝到库表中
            BeanUtils.copyProperties(scrVO, scrEntity);
            scrEntity.setIsValid("1");
            scrEntity.setExtend1("CGCS2000");
            scrs.add(scrEntity);
            //saveOrUpdate(scrEntity);
        }
        System.out.println(new Date()+"-------------------4.开始保存--结束将VO数据映射拷贝到库表中");
        qhSiteClassResultInitial.newSqlBatchSaveEntities(scrs,createUser);
    }*/

    //保存--zyt
    private int newSaveData(String filePath, String province, String city, String area, String codeType, int dataLength, String createUser) {
        int count = qhSiteClassResultInitial.newSqlBatchSaveEntities(filePath,province,city,area,codeType,dataLength,createUser);

        return count;
    }
}
